home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / GNU / emacs.inst / emacs19.idb / usr / gnu / lib / emacs / site-lisp / su-edit.el.z / su-edit.el
Encoding:
Text File  |  1994-08-02  |  2.2 KB  |  53 lines

  1. ;; From jr@bbn.com Fri Sep 22 18:15:02 1989
  2. ;; added blanking passwd, Sep 22 18:20 -- tale
  3.  
  4. ;;; suggested binding (# is the prompt when superuser):
  5. ;;; (global-set-key "\e#" 'su-command)
  6.  
  7. (defun su-command (password command)
  8.   "Prompt for root password and a command, then do the latter as root."
  9.   (interactive (list (read-passwd "root password: ")
  10.                      (read-string "shell command: ")))
  11.   (let ((buffer (get-buffer-create "*Shell Command Output*"))
  12.         proc)
  13.     (save-excursion
  14.           (set-buffer buffer)
  15.           (erase-buffer))
  16.     (setq proc (start-process "su-emacs" buffer "/bin/su" "-c" command))
  17.     (if (save-excursion
  18.           (set-buffer buffer)
  19.           (goto-char (point-min))
  20.           (while (not (looking-at "Password:"))
  21.             (accept-process-output proc)
  22.             (goto-char (point-min)))
  23.           (erase-buffer)
  24.           (send-string proc (concat password "\n"))
  25.           (while (not (looking-at "\n"))
  26.             (accept-process-output proc)
  27.             (goto-char (point-min)))
  28.           (delete-char 1)
  29.           (while (not (equal (process-status proc) 'exit))
  30.             (accept-process-output))
  31.           (> (buffer-size) 0))
  32.         (set-window-start (display-buffer buffer) 1)
  33.       (message "(Command completed with no output)"))))
  34.  
  35. (defun read-passwd (&optional prompt)
  36.   "Allow user to type a string without it showing.  Returns string.
  37. If optional PROMPT non-nil, use it as the prompt string in the minibuffer."
  38.   ;; this is based on a similar function in telnet.el
  39.   ;; the major drawback is that while being prompted for a password
  40.   ;; it stays in this routine until C-g, RET or LFD is typed.
  41.   ;; also didn't bother moving the cursor to the minibuffer
  42.   (let ((passwd "") (echo-keystrokes 0) char)
  43.     (if prompt (message prompt))
  44.     (while (not (or (= (setq char (read-char)) 13) (= char 10)))
  45.       ;; naughty bit.  take C-h to mean DEL.
  46.       (if (or (= char 8) (= char 127))
  47.           (if (> (length passwd) 0)
  48.               (setq passwd (substring passwd 0 (1- (length passwd)))))
  49.         (setq passwd (concat passwd (char-to-string char))))
  50.       (if prompt (message (concat prompt (make-string (length passwd) ?*)))))
  51.     (if prompt (message ""))
  52.     passwd))
  53.